﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HCSExtensions.Enums;

namespace HCSExtensions
{
    public class TransactionEvent
    {
        public TransactionEvent()
        {
            this.IsSuccess = true;
        }

        private object _ReturnObject { get; set; }
        public object ReturnObject
        {
            get
            {
                return this._ReturnObject;
            }
            set
            {
                this._ReturnObject = value;
            }
        }
        private Exception _Exception { get; set; }
        public Exception Exception
        {
            get
            {
                return this._Exception;
            }
            set
            {
                this.TransactionType = TransactionType.Fail;
                this.IsSuccess = false;
                this._Exception = value;
            }
        }
        private bool _IsSuccess { get; set; }
        public bool IsSuccess
        {
            get
            {
                return this._IsSuccess;
            }
            set
            {
                //if (value)
                //{
                //    this.TransactionType = TransactionTypes.Success;
                //}
                this._IsSuccess = value;
            }
        }
        private string _ErrorMessage { get; set; }
        public string ErrorMessage
        {
            get
            {
                return this._ErrorMessage;
            }
            set
            {
                this.TransactionType = TransactionType.OperationalError;
                this._ErrorMessage = value;
            }
        }
        private TransactionType _TransactionType { get; set; }
        public TransactionType TransactionType
        {
            get
            {
                return this._TransactionType;
            }
            set
            {
                this.IsSuccess = (value == TransactionType.Success);
                this._TransactionType = value;
            }
        }

        public string FullErrorMessage
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ErrorMessage))
                {
                    return ErrorMessage;
                }

                if (this.Exception != null)
                {
                    return this.Exception.ToString();
                }

                return "Bilinmeyen bir hata oluştu.";
            }
        }

        public byte ErrorCode { get; set; }
    }
}
